<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="padding-top:10px;" v-show="showTab">
      <el-form :inline="true" :model="filters" :size="size" ref="filters" label-width="100px">
        <el-form-item prop="username" label="用户账号">
          <el-input v-model="filters.username" placeholder="用户账号"></el-input>
        </el-form-item>
        <el-form-item prop="telephone" label="手机号">
          <el-input v-model="filters.mobile" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item prop="startIntegration" label="积分值启">
          <el-input v-model="filters.startIntegration" placeholder="积分值启"></el-input>
        </el-form-item>
        <el-form-item prop="endIntegration" label="积分值止">
          <el-input v-model="filters.endIntegration" placeholder="积分值止"></el-input>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
          <el-form-item style="float:right"> 
            <el-button-group>
              <el-tooltip content="刷新" placement="top">
                <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
              </el-tooltip>
              <el-tooltip content="列显示" placement="top">
                <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
              </el-tooltip>
              <el-tooltip content="导出" placement="top">
                <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
              </el-tooltip>
            </el-button-group>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;"  v-show="!showTab">
      <el-form :inline="true" :model="filtersFlow" :size="size" ref="filtersFlow">
        <el-form-item prop="startIntegration">
          <el-input v-model="filters.startIntegration" placeholder="积分值启"></el-input>
        </el-form-item>
        <el-form-item prop="endIntegration">
          <el-input v-model="filters.endIntegration" placeholder="积分值止"></el-input>
        </el-form-item>
        <el-form-item label="变动类型" prop="trans_type">
          <el-select v-model="filters.trans_type" placeholder="变动类型" style="width: 100%">
            <el-option
              v-for="item in transType"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      :totalSize="totalSize"
      :showEditOperation="false"
      :showBatchDelete="false"
      :showDeleteOperation="false"
      :showCustomOperation="true"
      :customLabel='text'
      @findPage="findPage"
      @handleCustom="handleDetail"
      ref="CyTable"
    ></cy-table>
  </div>
</template>

<script>
import CyTable from "@/views/Core/JicTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      text:'查看',
      filters: {
        username: "",
        mobile: "",
        startIntegration: "",
        endIntegration: "",
        t: "member",
        trans_type:''
      },
      filtersFlow: {
        username: "",
        telephone: "",
        startIntegration: "",
        endIntegration: "",
        memberId: "",
        id: ""
      },
      showTab:true,
      // 1、积分开户,2、积分添加,3、积分消费, 4、积分冻结(暂不实现),5、积分冻结添加,6、积分冻结解冻，7、积分过期 ,8、退货积分变更
      transType: [{name: '积分开户',id: 1}, {name: '积分添加',id: 2}, {name: '积分消费',id: 3},  {name: '积分冻结',id: 4},{name:"积分冻结添加",id:5},{name:"积分冻结解冻",id:6},{name:"积分过期",id:7},{name:"退货积分变更","id":8}],
      columns: [
        { prop: "id", label: "ID", minWidth: 50 },
        { prop: "username", label: "用户名", minWidth: 100 },
        { prop: "mobile", label: "手机号", minWidth: 100 },
        { prop: "integration", label: "当前积分", minWidth: 80 },
        { prop: "freezeIntegral", label: "冻结积分", minWidth: 120 }
      ],
      filterColumns: [],
      pageRequest: {pageNum: 1, pageSize: 10},
      pageResult: [],
      totalSize: 0,
      pageRequest: { pageNum: 1, pageSize: 10 },

    };
  },
  methods: {
    // 获取分页数据
    findPage: function (data) {
      let this_ = this;
      if (this_.filters == undefined || this_.filters == null) {
        this_.filters = {};
      }
      this_.filters.start = this.pageRequest.pageNum;
      this_.filters.limit = this.pageRequest.pageSize;
      this.utils.request.queryMemberList(this_.filters, function (res) {
        if (res.data.rows == null) {
          res.data.rows = [];
        }
        this_.$refs.CyTable.findPage({content:res.data.rows,total:res.data.total});
        // this_.pageResult = res.data.rows;
        // this_.totalSize = Number(res.data.total);

      });
    },
    
    findPagePointsLog: function (data) {
      console.log(data)
      let this_ = this;
      if (this_.filters == undefined || this_.filters == null) {
        this_.filters = {};
      }
      this_.filters.memberId = data.memberId;
      this_.filters.start = this.pageRequest.pageNum;
      this_.filters.limit = this.pageRequest.pageSize;
      this.utils.request.queryPointsLogList(this_.filters, function (res) {
        if (res.data.rows == null) {
          res.data.rows = [];
        }
        this_.$refs.CyTable.findPage({content:res.data.rows,total:res.data.total});
        // this_.pageResult = res.data.rows;
        // this_.totalSize = Number(res.data.total);

      });
    },
    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },

    handleDetail(params){
        console.log(params);
        if(this.showTab == true){
            this.showTab = false;
            this.columns=[
                { prop: "transType", label: "积分变动详情", minWidth: 100 },
                { prop: "telephone", label: "渠道", minWidth: 100 },
                { prop: "freezeTrans", label: "变动积分", minWidth: 80 },
                { prop: "freeze_integral", label: "余额", minWidth: 120 },
                { prop: "freeze_integral", label: "积分变动时间", minWidth: 120 },
                { prop: "freeze_integral", label: "积分状态", minWidth: 120 }
            ];
            this.text = '返回';
            this.filtersFlow.memberId=params.row.id;
            this.initColumns()
            this.findPagePointsLog(this.filtersFlow);
        }else if(this.showTab == false){
            this.showTab = true;
             this.columns=[
                { prop: "id", label: "ID", minWidth: 50 },
                { prop: "username", label: "用户名", minWidth: 100 },
                { prop: "mobile", label: "手机号", minWidth: 100 },
                { prop: "integration", label: "当前积分", minWidth: 80 },
                { prop: "freezeIntegral", label: "冻结积分", minWidth: 120 }
            ];
            this.text = '查看';
            this.initColumns()
            this.findPage(this.filters);
        }
    },

    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      var temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "系统参数下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },
  mounted() {
    //   this.columns = 
	  this.initColumns()
  }
};
</script>

<style scoped>
</style>